package com.example.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sys.entity.*;
import com.example.sys.mapper.RoleMapper;
import com.example.sys.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sys.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色信息表 服务实现类
 * </p>
 *
 * @author anan
 * @since 2019-06-17
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> findRoleByLoginName(String loginName) {
        return roleMapper.findRoleByLoginName(loginName);
    }

    @Override
    public List<Role> findRoleByUserId(Long userId) {
        return roleMapper.findRoleByUserId(userId);
    }

    @Override
    public IPage<Role> selectPage(RoleVo roleVo) {
        IPage<Role> iPage = new Page<>(roleVo.getPage(),roleVo.getLimit());
        QueryWrapper<Role> wrapper = new QueryWrapper<>();
        if (!StrUtil.hasEmpty(roleVo.getRoleName()))
            wrapper.like("role_name", roleVo.getRoleName());
        if (!StrUtil.hasEmpty(roleVo.getRoleKey()))
            wrapper.like("role_key", roleVo.getRoleKey());
        return roleMapper.selectPage(iPage, wrapper);
    }

    @Override
    public List<RoleMenu> getMenuList(Long roleId) {
            return roleMapper.getMenuList(roleId);
    }

    @Override
    public List<UserRole> getUserList(Long roleId) {
        return roleMapper.getUserList(roleId);
    }

    @Override
    public List<RoleDept> getDeptList(Long roleId) {
        return roleMapper.getDeptList(roleId);
    }
}
